import getIn from '../../sdk/utils/getIn';
import { API_ARTICLE_CATE, API_ARTICLE_DETAIL } from '../../sdk/business/url.js';
import { showSuccess, showFail } from '../../utils/util';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuItems: [
      { cate_name: "视频案例", id: 1, nature: 0 },
      { cate_name: "热门案例", id: 1, nature: 1 }
    ],
    currentIndex: 0,
    loading: false,
    showList: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ showList: false }, () => {
      this.articleList = this.selectComponent("#videolist");
      this.articleList.show(1, "视频案例");
    })
  },
  // 点击menu回调函数
  menuCallBackAction (e) {
    const index = getIn(e, ['detail']);
    const { menuItems, currentIndex } = this.data;
    if (currentIndex != index && !this.data.loading) {
      const id = menuItems[index].id;
      wx.setNavigationBarTitle({
        title: menuItems[index].cate_name
      });
      if (!menuItems[index].nature) {
        this.setData({ currentIndex: index, showList: false }, () => {
          this.articleList = this.selectComponent("#videolist");
          this.articleList.show(id, menuItems[index].cate_name);
        })
      } else {
        this.setData({ currentIndex: index, showList: true }, () => {
          this.articleList = this.selectComponent("#caseList");
          this.articleList.show(id, menuItems[index].cate_name);
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})